package git_cmd

import (
	"fmt"
	"os/exec"

	"atomgit.com/openlinksaas/gitwrap/utils"
	"github.com/spf13/cobra"
)

var _StashPopGit = &cobra.Command{
	Use: "stashPop",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) != 1 {
			utils.OutputError(fmt.Errorf("need param [index]"))
			return
		}
		index := args[0]
		cmdPath, err := exec.LookPath("git")
		if err != nil {
			utils.OutputError(err)
			return
		}

		gitCmd := exec.Command(cmdPath, "stash", "pop", index)
		gitCmd.Dir = gitFlagLocalPath
		_, err = gitCmd.Output()
		if err != nil {
			utils.OutputError(err)
			return
		}
		utils.OutputData("")
	},
}
